import json

from redis import ConnectionPool, Redis

class RedisHandle:
    #连接数据库
    def __init__(self, host, port, password, db):

        self.host = host
        self.port = port
        self.password = password
        pool = ConnectionPool(host=self.host, port=self.port, db=db, password=self.password,decode_responses=True)
        self.client = Redis(connection_pool=pool)

    #获取所有keys
    def GetAllKeys(self):
        keys = self.client.keys()
        return keys
    #获取指定key的值
    def GetKey(self,key):
        value = self.client.get(key)
        return value
    #修改指定key的值
    def SetKey(self,key,NewValue):
        self.client.set(key, NewValue)

    def deleteKey(self, key):
        self.client.delete(key)


